import ChooseQuestion from "@/views/components/ChooseQuestion/index.vue";
import ShowFileList from "@/components/ShowFileList/index.vue";
import HiddenDangerInfo from "@/views/checkBusPage/components/hiddenDangerInfo/index.vue";
import ChooseEnterprise from "@/views/components/ChooseEnterprise/index.vue";
import {HIDDEN_DANGER_WIDTH} from "@/constantData";
import ValueTable from "@/components/ValueTable/index.vue";
import {isArr} from "@/utils/arrayUtil";

const infoPageMixins = {
  components: {
    ChooseQuestion,
    ShowFileList,
    HiddenDangerInfo,
    ChooseEnterprise,
    ValueTable
  },
  props: {
    danInfoData: {
      type: Object
    }
  },
  data() {
    const checkItems = (rule, value, callback) => {
      return isArr(value) ? callback() : callback(new Error('隐患列表不能为空'));
    };
    return {
      HIDDEN_DANGER_WIDTH,
      addDrawWidth: '50%',
      questionValueTableConfig: [
        {
          label: '隐患描述',
          value: 'questionDesc',
          type: 'txtArea',
          required: true,
        },
        {
          label: '隐患分类',
          value: 'questionTypeCode',
          type: 'choose-question',
          required: true,
        },
        {
          label: '整改建议',
          value: 'suggestion',
          type: 'txtArea',
          required: true,
        },
        {
          label: '整改前附件',
          value: 'fileIds',
          type: 'file',
          required: false,
        },
      ],
      fileFiled: 'fileVos',
      // 查询参数
      queryParams: {
        // 隐患类别
        questionTypeCode: null,
        // 整改状态
        repairState: null,
      },
      otherQueryParam: {
        inspectId: this.inspectInfo.id,
      },
      editOpen: false,
      editTitle: '',
      baseForm: {
        id: null,
        // 所属企业代码
        enterpriseSerial: null,
        // 检查id
        inspectId: this.inspectInfo.id,
        // 隐患
        items: [],
      },
      rules: {
        enterpriseSerial: [
          {required: true, message: "抽查企业不能为空", trigger: "change11"}
        ],
        items: [
          {required: true, message: "隐患列表不能为空", trigger: "change"}
        ]
      },
    }
  },
  watch: {
    fileList(val) {
      this.form.fileIds = isArr(val) ? val.map(file => file.fileId) : [];
    }
  },
  methods: {
    endFun() {
      this.editOpen = false
    }
  }
}

export {infoPageMixins}
